﻿namespace XmlConverter
{
	class Keygen<T>
	{
		T _last_value;
		readonly Generator _generator;

		public Keygen(Generator generator)
		{
			_generator = generator;
		}

		public delegate T Generator(T previous);

		public Keygen(T initial, Generator generator)
		{
			_last_value = initial;
			_generator = generator;
		}

		public T Next()
		{
			var result = _last_value;
			_last_value = _generator(_last_value);

			return result;
		}
	}
}